/* 
 * File:   MenuGame.cpp
 * Author: agu
 * 
 * Created on 16 de junio de 2014, 17:20
 */
#include <iostream>
#include "client_MenuGame.h"


MenuGame::MenuGame() {
    this->builder = Gtk::Builder::create();
    try {
        this->builder->add_from_file("gladeInterfaces/menuGame.glade");
    } catch (const Glib::FileError& ex) {
        std::cout << "FileError: " << ex.what() << std::endl;

    } catch (const Glib::MarkupError& ex) {
        std::cout << "MarkupError: " << ex.what() << std::endl;

    } catch (const Gtk::BuilderError& ex) {
        std::cout << "BuilderError: " << ex.what() << std::endl;

    }

}

void MenuGame::loadWidgets() {
    this->builder->get_widget("window", this->window);
    this->builder->get_widget("buttonNew", this->buttonNew);
    this->builder->get_widget("buttonBack", this->buttonBack);
    this->builder->get_widget("buttonJoin", this->buttonJoin);

}

void MenuGame::connectWidgets() {
    this->window->signal_hide().connect(sigc::mem_fun(this, &MenuGame::close));
    this->buttonBack->signal_clicked().connect(sigc::mem_fun(this, &MenuGame::back));
    this->buttonNew->signal_clicked().connect(sigc::mem_fun(this, &MenuGame::newGame));
    this->buttonJoin->signal_clicked().connect(sigc::mem_fun(this, &MenuGame::join));
}

MenuGame::~MenuGame() {    
     
}

void MenuGame::run() {

        this->loadWidgets();
    this->connectWidgets();
    this->window->show();
}

void MenuGame::close() {    
    this->window->close();
}

void MenuGame::back() {
    this->window->set_visible(false);
    this->windowsBack->set_visible(true);
}

void MenuGame::newGame() {
    this->window->set_visible(false);
    this->menuNewGame.setSocket(this->socket);
    this->menuNewGame.setWindowsBack(this->window);
    this->menuNewGame.run();
}

void MenuGame::join() {
    this->window->set_visible(false);    
    this->campaignList.setSocket(this->socket);
    this->campaignList.setWindowsBack(this->window);
    this->campaignList.run();
}

void MenuGame::setWindowsBack(Gtk::Window *windowBack) {
    this->windowsBack = windowBack;
}

void MenuGame::setSocket(Client_socket s) {
    this->socket = s;
}
